//
//  DYGroupingResultsCell.m
//  DaYing
//
//  Created by DaYing Team on 2023.
//  Copyright © 2023 DaYing Team. All rights reserved.
//

#import "DYGroupingResultsCell.h"

@implementation DYGroupingResultsCell

- (void)awakeFromNib {
    // Initialization code
    [super awakeFromNib];
}

- (void)setData:(id)data delegate:(id)delegate {
    
    if ([data isKindOfClass:[NSDictionary class]]) {
        if ([data[@"data"] isKindOfClass:[DYGroupingResultsCellModel class]]) {
            DYGroupingResultsCellModel *model = data[@"data"];
            _model = model;
            _titleLabel.text = [NSString stringWithFormat:@"名称：%@",model.name];
            __block NSString *title = [NSString stringWithFormat:@"分组个数：%@\n分组内容：【",model.count];
            [_model.groupList enumerateObjectsUsingBlock:^(NSString *str, NSUInteger idx, BOOL * _Nonnull stop) {
                if (idx == 0) {
                    title = [NSString stringWithFormat:@"%@%@",title,str];
                } else {
                    title = [NSString stringWithFormat:@"%@, %@",title,str];
                }
            }];
            title = [NSString stringWithFormat:@"%@】",title];
            _contentLabel.text = title;
        }
    }
}

+ (float)getCellFrame:(id)msg {
    
    if ([msg isKindOfClass:[DYGroupingResultsCellModel class]]) {
        DYGroupingResultsCellModel *model = msg;
        
        __block NSString *title = [NSString stringWithFormat:@"分组内容：【"];
        [model.groupList enumerateObjectsUsingBlock:^(NSString *str, NSUInteger idx, BOOL * _Nonnull stop) {
            if (idx == 0) {
                title = [NSString stringWithFormat:@"%@%@",title,str];
            } else {
                title = [NSString stringWithFormat:@"%@, %@",title,str];
            }
        }];
        title = [NSString stringWithFormat:@"%@】",title];
        
        CGSize titleSize = [title ex_sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake(kScreenWidth, MAXFLOAT)];
        
        return 120 + titleSize.height;
    }
    
    return 60;
}

@end


#pragma mark - Model

@implementation DYGroupingResultsCellModel

+ (DYGroupingResultsCellModel *)ittemModelWithName:(NSString *)name count:(NSString *)count groupList:(NSArray *)groupList {
    DYGroupingResultsCellModel *model = [DYGroupingResultsCellModel new];
    model.name = name.length > 0 ? name : @"";
    model.count = count.length > 0 ? count : @"";
    model.groupList = groupList;
    return model;
}

@end
